package genome;

public class FunctionSet {
	
	public int NUM_FUNCTIONS = 4;
	public int ARITY = 2;
	
	private static double tol = 1.0E-8; //tolerance value to account for machine error
	
	//basic numerical function set
	
	public String toString(){
		return "FunctionSet";
	}
	
	public double func(double[] c,int function){
		
		double c0 = c[0];
		double c1 = c[1];
		
		switch(function){
			case 0 :
				//ADD
				return c0+c1;
			
			case 1 :
				//SUB
				return c0-c1;
				
			case 2 :
				//MULT
				return c0*c1;
				
			case 3 :
				//DIV
				if(c1 < tol && c1 > -tol){
					return 1.0;
				}
				else {
					return c0/c1;
				}
				
			default :
				//0.0
				return 0.0;
		}
	}
	
	public String getfString(String[] s, int function){
		//All functions are at least biarity, so always evaluate these.
		
		String s0 = s[0];
		String s1 = s[1];
		
		switch(function){
			case 0 :
				return "["+s0+"+"+s1+"]";
			
			case 1 :
				return "["+s0+"-"+s1+"]";
				
			case 2 :
				return "["+s0+"*"+s1+"]";
			
			case 3 :
				return "["+s0+"/"+s1+"]";
			
			default :
				return "0.0";
		}
	}
}
